package com.chara.rabbitmq_demo.com.chara.rabbitmq.routingKey;

import com.chara.rabbitmq_demo.com.chara.rabbitmq.utils.ConnectionUtil;
import com.rabbitmq.client.*;

import java.io.IOException;

/**
 * @Classname Consumer1
 * @Description 路由key消费者1
 * @Date 2025/10/9 22:07
 * @Author Chara
 */
public class Consumer1 {

    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();

        Channel channel = connection.createChannel();

        String queueName = "direct_queue1";

        channel.queueDeclare(queueName, true, false, false, null);

        Consumer consumer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("body:" + new String(body));
                System.out.println("队列1消费者1将日志打印到控制台");
            }
        };

        channel.basicConsume(queueName, true, consumer);
    }

}
